package cn.stronglink.asset.module.resource.resource.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.plugins.Page;

import cn.stronglink.asset.model.Resource;
import cn.stronglink.asset.module.resource.resource.service.ResourceService;
import cn.stronglink.suite.core.base.AbstractController;
import cn.stronglink.suite.core.log.annotation.OperateLog;
import cn.stronglink.suite.core.log.annotation.OperateLog.OpType;

@Controller
@RequestMapping(value="resource")
public class ResourceController extends AbstractController{
	@Autowired
	private ResourceService resourceService;
	/**
	 * 新增资源
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param borrowReturn
	 * @return
	 */
	@OperateLog(module = "资源管理",desc="创建资源", type = OpType.ADD)
	@RequestMapping(value="create")
	public ResponseEntity<ModelMap> create(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Resource resource) {
		resourceService.create(resource);
		return setSuccessModelMap(modelMap,null);
	}
	
	/**
	 * 编辑资源
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param resourceGroup
	 * @return
	 */
	@OperateLog(module = "资源管理",desc="修改资源", type = OpType.UPDATE)
	@RequestMapping(value="edit")
	public ResponseEntity<ModelMap> edit(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Resource resource) {
		resourceService.edit(resource);
		return setSuccessModelMap(modelMap,null);
	}
	
	/**
	 * 移除资源
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param resourceGroup
	 * @return
	 */
	@OperateLog(module = "资源管理",desc="删除资源", type = OpType.DEL)
	@RequestMapping(value="remove")
	public ResponseEntity<ModelMap> remove(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response,@RequestBody Long id) {
		resourceService.remove(id);
		return setSuccessModelMap(modelMap,null);
	}
	
	/**
	 * 根据ip参数查询ip参数明细
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "qryById")
	public ResponseEntity<ModelMap> qryById(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Long id) {	
		Resource data =resourceService.qryById(id);
		return setSuccessModelMap(modelMap, data);
	}
	/**
	 * 查询资源列表带分页
	 * @param modelMap
	 * @param request
	 * @param response
	 * @param params
	 * @return
	 */
	@RequestMapping(value = "qryList")
	public ResponseEntity<ModelMap> qryList(ModelMap modelMap, HttpServletRequest request,
			HttpServletResponse response, @RequestBody Map<String,Object> params) {	
		@SuppressWarnings("unchecked")
		Page<Resource> page = (Page<Resource>) super.getPage(params);
		Page<Resource> data = resourceService.qryList(page,params);
		return setSuccessModelMap(modelMap, data);
	}
}
